package com.example.archive.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;

@Component
public class TokenUtil {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public Integer getUserIdFromToken(HttpServletRequest request) {
        String token = request.getHeader("token");
        if (token != null && !token.isEmpty()) {
            String userIdStr = stringRedisTemplate.opsForValue().get("login:" + token);
            if (userIdStr != null) {
                return Integer.parseInt(userIdStr);
            }
        }
        return null;
    }
} 